package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.R.bool;
import android.graphics.Bitmap;
import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.game.GameCarbon;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.game.TowerGameCarbon;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.game.item.ItemEquipment;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;
import com.handinfo.android.core.object.Animation;

public class UITowerCarbon implements IUIWindows {

	public DWFrame m_open_tower_carbon_frame = null;
	public DWImageBox m_list_ima = null;
	public DWLabel m_open_carbon_lable = null;
	public DWButton m_open_carbon_more_but = null;
	public DWButton m_open_carbon_begin_but = null;
	public Bitmap m_cr_xxbj = null;
	public Bitmap m_cr_tower_open = null;
	public Bitmap m_cr_tower_not_open = null;
	public Bitmap m_cr_tower_light = null;
	public Bitmap m_cr_but = null;
	public Bitmap m_cr_but_down = null;
	public Bitmap m_cr_tuichu = null;
	public DWTitle m_open_towergamecarbon_tit = null;
	public Bitmap m_cr_tit = null;
	public DWImageBox m_tit_ima = null;
	public DWImageBox m_tuichu_ima = null;
	public DWLabel m_lable_instead = new DWLabel("代替");
	public DWTextbox m_open_carbon_desc_text = null;
	public DWImageBox m_open_carbon_image[] = null;
	public DWBackground m_open_carbon_you_xbj = null;
	public Bitmap m_cr_xxxbj = null;
	public Bitmap m_cr_xxxbj_xz = null;

	/**
	 * 打开界面
	 */
	public byte m_size = 0; // 总层数
	public byte m_now_index = 0;// 所在层数
	// /打开塔式副本的界面
	String m_fuben_name[] = null;
	String m_fuben_desc[] = null;
	byte m_index_fuben[] = null;

	public void recvOpenTowerGamecarbon(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		Tools.debugPrintln("开启副本的状态(0失败，1成功)：" + m_state);
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抱歉，亲，您的等级还不够哦，加油。");
		} else if (m_state == 1) {
			m_size = dis.readByte();
			Tools.debugPrintln("总层数：" + m_size);
			m_fuben_name = new String[m_size];
			m_index_fuben = new byte[m_size];
			m_fuben_desc = new String[m_size];
			for (int i = 0; i < m_size; i++) {
				m_index_fuben[i] = dis.readByte();
				Tools.debugPrintln("索引值：" + m_index_fuben[i]);
				m_fuben_name[i] = dis.readUTF();
				Tools.debugPrintln("第" + i + "个的名字：" + m_fuben_name[i]);
				m_fuben_desc[i] = dis.readUTF();
				Tools.debugPrintln("第" + i + "个的描述：" + m_fuben_desc[i]);
			}
			m_now_index = dis.readByte();
			Tools.debugPrintln("所在层数：" + m_now_index);
			TowerGamebon();
		}
	}

	public void TowerGamebon() {
		if (DWControlsManager.getInstance().contains(m_open_tower_carbon_frame)) {
			if (m_open_tower_carbon_frame != null) {
				DWControlsManager.getInstance().removeControl(m_open_tower_carbon_frame);
			}
		}
		m_open_tower_carbon_frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_open_tower_carbon_frame.setClickClose(false);
		DWControlsManager.getInstance().addControl(m_open_tower_carbon_frame);

		m_open_towergamecarbon_tit = new DWTitle("", m_open_tower_carbon_frame);
		m_open_tower_carbon_frame.addControl(m_open_towergamecarbon_tit);
		m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_open_towergamecarbon_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_open_tower_carbon_frame.addControl(m_tit_ima);

		m_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima.setTouchZoomIn(20, 20);
		m_tuichu_ima.setNearAnchor(m_open_towergamecarbon_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_open_tower_carbon_frame.addControl(m_tuichu_ima);
		m_tuichu_ima.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWControlsManager.getInstance().removeControl(m_open_tower_carbon_frame);
			}
		});

		m_list_ima = new DWImageBox(m_cr_xxbj);
		m_list_ima.setNearAnchor(
				m_open_tower_carbon_frame,
				Tools.LEFT_TOP,
				Tools.LEFT_TOP,
				(m_open_tower_carbon_frame.getShowWidth() - m_cr_xxbj.getWidth() - 2 * m_cr_but.getWidth() - 20) / 3,
				(m_open_towergamecarbon_tit.getShowHeight() - 20));
		m_open_tower_carbon_frame.addControl(m_list_ima);

		m_open_carbon_image = new DWImageBox[m_size];
		int m_x = m_cr_tower_open.getWidth() / 2;
		int m_y = m_cr_tower_open.getHeight() / 2;
		Tools.debugPrintln("m_x:" + m_x);
		Tools.debugPrintln("m_y:" + m_y);
		for (int i = 0; i < m_open_carbon_image.length; i++) {
			if (i < m_now_index) {
				m_open_carbon_image[i] = new DWImageBox(m_cr_tower_open);
			} else if (i == m_now_index) {
				m_open_carbon_image[i] = new DWImageBox(m_cr_tower_light);
			} else {
				m_open_carbon_image[i] = new DWImageBox(m_cr_tower_not_open);
			}
			int[][] points = { { 116, 325 }, { 242, 347 }, { 369, 307 }, { 448, 212 }, { 314, 202 }, { 188, 197 }, { 70, 128 }, { 196, 92 }, { 346, 75 }, { 464, 98 } };
			int multiple = DWGameManager.AdpaterType == DWGameManager.AD_HIGH ? 15 : 10;
			m_open_carbon_image[i].setNearAnchor(m_list_ima, Tools.HCENTER_VCENTER, Tools.LEFT_TOP, points[i][0] * multiple / 10, points[i][1] * multiple / 10);
			m_open_tower_carbon_frame.addControl(m_open_carbon_image[i]);
			final int m_index = i;
			m_open_carbon_image[i].addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					SendLose(m_index);
				}
			});
		}

		m_open_carbon_lable = new DWLabel("点击每层查看奖励");
		m_open_carbon_lable.setShowWideHigh(m_open_tower_carbon_frame.getShowWidth() - 30, m_open_carbon_lable.getShowHeight());
		m_open_carbon_lable.setNearAnchor(m_list_ima, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 0);
		m_open_carbon_lable.setTextColor(Tools.ORANGE);
		m_open_carbon_lable.setBackgroundColor(Tools.ALPHA);
		m_open_tower_carbon_frame.addControl(m_open_carbon_lable);

		m_open_carbon_you_xbj = new DWBackground(2 * m_cr_but.getWidth() + 20, m_list_ima.getShowHeight() - m_cr_but.getHeight() - 20);
		m_open_carbon_you_xbj.setNearAnchor(m_list_ima, Tools.LEFT_TOP, Tools.RIGHT_TOP, (m_open_tower_carbon_frame.getShowWidth() - m_cr_xxbj.getWidth() - 2 * m_cr_but.getWidth() - 20) / 3, 10);
		m_open_carbon_you_xbj.setFill(true);
		m_open_tower_carbon_frame.addControl(m_open_carbon_you_xbj);

		m_open_carbon_desc_text = new DWTextbox("<mark c=FFBB11>" + m_fuben_name[m_now_index] + "</mark>" + DWControlTools.CHANGE_ROW + m_fuben_desc[m_now_index],
				m_open_carbon_you_xbj.getShowWidth() - 20, m_open_carbon_you_xbj.getShowHeight() - 30);
		m_open_carbon_desc_text.setNearAnchor(m_open_carbon_you_xbj, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_open_tower_carbon_frame.addControl(m_open_carbon_desc_text);

		m_open_carbon_more_but = new DWButton("重新开始", m_cr_but);
		m_open_carbon_more_but.setDownImage(m_cr_but_down);
		m_open_carbon_more_but
				.setNearAnchor(m_list_ima, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, (m_open_tower_carbon_frame.getShowWidth() - m_cr_xxbj.getWidth() - 2 * m_cr_but.getWidth() - 20) / 3, 0);
		m_open_carbon_more_but.addListener(m_more_but_lis);
		m_open_tower_carbon_frame.addControl(m_open_carbon_more_but);

		m_open_carbon_begin_but = new DWButton("开始挑战", m_cr_but);
		m_open_carbon_begin_but.setDownImage(m_cr_but_down);
		m_open_carbon_begin_but.setNearAnchor(m_open_carbon_more_but, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 20, 0);
		m_open_carbon_begin_but.addListener(m_begin_but_lis);
		m_open_tower_carbon_frame.addControl(m_open_carbon_begin_but);
	}

	private DWListener m_more_but_lis = new DWListener() {
		public void OnDoubleClick() {
		}

		public void OnClick() {
			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "将重置当前的记录,您确定要重新开始挑战?", "确定", "返回");
			DWControlsManager.getInstance().addControl(m_mb);
			m_mb.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
						DWGameManager.getInstance().getSendMessage().sendTowerMoreGameCarbon();
					} else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
					}
					DWControlsManager.getInstance().removeControl(m_mb);
				}
			});
		}
	};
	private DWListener m_begin_but_lis = new DWListener() {
		public void OnDoubleClick() {
		}

		public void OnClick() {

			// /发送进入塔式副本的指令.
			DWGameManager.getInstance().getSendMessage().sendTowerGamecarbonJoin();
		}
	};

	// /发送请求此副本掉落状况的指令
	int m_chuandi_index = 0;

	public void SendLose(int index) {
		DWGameManager.getInstance().getSendMessage().sendTowerGamecarbonJiang((byte) index);
		m_chuandi_index = index;
	}

	/**
	 * 每层的副本的掉落接收数据
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public CopyOnWriteArrayList<TowerGameCarbon> m_tower_list = new CopyOnWriteArrayList<TowerGameCarbon>();

	public void recvLoseJiangLi(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		m_tower_list.clear();
		TowerGameCarbon m_tower = new TowerGameCarbon();
		m_tower.recvMoney(dis);
		m_tower.recvItem(dis);
		m_tower_list.add(m_tower);
		Lose(m_chuandi_index);
	}

	/**
	 * 副本掉落的界面
	 */
	public DWFrame m_lose_frame = null;
	public DWListbox m_lose_listbox;
	public DWBackground m_ima_bg[];
	public DWTextbox m_lose_textbox[];
	public DWListSubItem m_lsi = null;
	public Bitmap m_cr_tit_ima = null;
	public Bitmap m_cr_grid = null;
	public DWGrid m_grid[] = null;

	public void Lose(int index) {
		if (DWControlsManager.getInstance().contains(m_lose_frame)) {
			if (m_lose_frame != null) {
				DWControlsManager.getInstance().removeControl(m_lose_frame);
			}
		}
		m_lose_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_lose_frame.setClickClose(false);
		DWControlsManager.getInstance().addControl(m_lose_frame);

		DWTitle m_lose_tit = new DWTitle("", m_lose_frame);
		m_lose_frame.addControl(m_lose_tit);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit_ima);
		m_tit_ima.setNearAnchor(m_lose_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_lose_frame.addControl(m_tit_ima);

		DWImageBox m_tuichu_ima_1 = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima_1.setNearAnchorUn(m_lose_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_lose_frame.addControl(m_tuichu_ima_1);
		m_tuichu_ima_1.setTouchZoomIn(40, 40);
		m_tuichu_ima_1.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWControlsManager.getInstance().removeControl(m_lose_frame);
			}
		});

		DWBackground m_xbj = new DWBackground(m_lose_frame.getShowWidth() - 20, m_lose_frame.getShowHeight() - (m_lose_tit.getShowHeight() - 20) - 20);
		m_xbj.setNearAnchor(m_lose_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10 + (m_lose_tit.getShowHeight() - 20));
		m_lose_frame.addControl(m_xbj);

		DWBackground m_name_bg = new DWBackground(m_cr_xxxbj, m_xbj.getShowWidth() - 10, 50);
		m_name_bg.setNearAnchor(m_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 5, 5);
		m_lose_frame.addControl(m_name_bg);

		DWTextbox m_carbon_name = new DWTextbox(m_fuben_name[index]);
		m_carbon_name.setNearAnchor(m_name_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_lose_frame.addControl(m_carbon_name);

		m_lose_listbox = new DWListbox(m_name_bg.getShowWidth(), m_xbj.getShowHeight() - m_name_bg.getShowHeight() - 10);
		m_lose_listbox.setNearAnchor(m_name_bg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 0);
		m_lose_listbox.setLineSpacing(10);
		m_lose_listbox.setShowBackgroundRect(false);
		m_lose_frame.addControl(m_lose_listbox);

		m_ima_bg = new DWBackground[m_tower_list.get(0).m_itemsize];
		m_grid = new DWGrid[m_tower_list.get(0).m_itemsize];
		m_lose_textbox = new DWTextbox[m_tower_list.get(0).m_itemsize];
		for (int m_lsi_index = 0; m_lsi_index < m_tower_list.get(0).m_itemsize; m_lsi_index++) {
			m_ima_bg[m_lsi_index] = new DWBackground(m_cr_xxxbj, (m_lose_listbox.getShowWidth() - 10) / 2, (m_lose_listbox.getShowHeight() - 20) / 3);
			m_grid[m_lsi_index] = new DWGrid(m_cr_grid);
			m_grid[m_lsi_index].m_data = m_tower_list.get(0).m_item_list[m_lsi_index];
			final int m_index = m_lsi_index;
			m_grid[m_lsi_index].addListener(new DWListener() {

				public void OnDoubleClick() {

				}

				public void OnClick() {
					for (int i = 0; i < m_tower_list.get(0).m_itemsize; i++) {
						m_grid[i].setSelect(false);
						m_ima_bg[i].setBackground(m_cr_xxxbj, false);
					}
					m_grid[m_index].setSelect(true);
					m_ima_bg[m_index].setBackground(m_cr_xxxbj_xz, false);
					DiaoLuo(m_tower_list.get(0).m_item_list[m_index].m_key);
					Tools.debugPrintln("下标：" + m_index);
					Tools.debugPrintln("发送的道具的key:" + m_tower_list.get(0).m_item_list[m_index].m_key);
				}
			});
			m_lose_textbox[m_lsi_index] = new DWTextbox("<mark c=" + getcolor(m_tower_list.get(0).m_item_list[m_lsi_index].m_quality) + ">" + m_tower_list.get(0).m_item_list[m_lsi_index].m_name
					+ "</mark>", m_ima_bg[m_lsi_index].getShowWidth() - m_grid[m_lsi_index].getShowWidth() - 5);
			if (m_lsi_index % 2 == 0) {
				m_lsi = new DWListSubItem();
				m_ima_bg[m_lsi_index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				m_grid[m_lsi_index].setNearAnchor(m_ima_bg[m_lsi_index], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
				m_lose_textbox[m_lsi_index].setNearAnchor(m_grid[m_lsi_index], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
				m_lsi.addControls(m_ima_bg[m_lsi_index]);
				m_lsi.addControls(m_grid[m_lsi_index]);
				m_lsi.addControls(m_lose_textbox[m_lsi_index]);
				if (m_lsi_index == (m_tower_list.get(0).m_itemsize - 1)) {
					m_lose_listbox.addSubItem(m_lsi);
				}
			} else {
				m_ima_bg[m_lsi_index].setNearAnchor(m_ima_bg[m_lsi_index - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);
				m_grid[m_lsi_index].setNearAnchor(m_ima_bg[m_lsi_index], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
				m_lose_textbox[m_lsi_index].setNearAnchor(m_grid[m_lsi_index], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
				m_lsi.addControls(m_ima_bg[m_lsi_index]);
				m_lsi.addControls(m_grid[m_lsi_index]);
				m_lsi.addControls(m_lose_textbox[m_lsi_index]);
				m_lose_listbox.addSubItem(m_lsi);
			}
		}
	}

	public void DiaoLuo(String key) {
		DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(0, key);
	}

	public void GridPoint() {
		for (int i = 0; i < 10; i++) {
			float x = (float) Math.sin(i * (360 / 10) + 0);
			float y = (float) Math.cos(i * (360 / 10) + 0);
			int m_x = m_buff_grid[i].getShowX();
			int m_y = m_buff_grid[i].getShowY();
			float targetX = m_x + m_buff_grid[i].getShowWidth() / 2 - (x * 160);
			float targetY = m_y + m_buff_grid[i].getShowWidth() / 2 + (y * 160);
			m_buff_grid[i].setPoint((int) targetX, (int) targetY);
		}
	}

	// //转盘开启接收指令
	public byte m_buff_size = 0;
	public boolean m_flag[] = null;// 判定是否是被锁定(false是未被锁定，true是被锁定)
	public int m_sigle_price = 0;
	CopyOnWriteArrayList<TowerGameCarbon> m_buff = new CopyOnWriteArrayList<TowerGameCarbon>();// /这个数组里面存了m_buff_size的长度的TowerGameCarbon对象

	public void recvTowerZhuanPanOpen(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		m_buff_size = dis.readByte();
		Tools.debugPrintln("buff的总个数：" + m_buff_size);
		m_flag = new boolean[m_buff_size];
		m_buff.clear();
		for (int i = 0; i < m_buff_size; i++) {
			m_flag[i] = false;
			TowerGameCarbon m_buff_tower = new TowerGameCarbon();
			m_buff_tower.m_buff_index = dis.readByte();
			Tools.debugPrintln("第" + i + "个buff的索引值：" + m_buff_tower.m_buff_index);
			m_buff_tower.m_buff_item.m_key = dis.readUTF();
			Tools.debugPrintln("第" + i + "个buff的key：" + m_buff_tower.m_buff_item.m_key);
			m_buff_tower.m_buff_item.m_name = dis.readUTF();
			Tools.debugPrintln("第" + i + "个buff的name：" + m_buff_tower.m_buff_item.m_name);
			m_buff_tower.m_buff_item.m_iconId = dis.readShort();
			Tools.debugPrintln("第" + i + "个buff的iconid：" + m_buff_tower.m_buff_item.m_iconId);
			m_buff_tower.m_buff_item.m_icon = IconManger.getInstance().getIcon(m_buff_tower.m_buff_item.m_iconId);
			m_buff_tower.m_buff_type = dis.readByte();
			Tools.debugPrintln("第" + i + "个buff的type：" + m_buff_tower.m_buff_type);
			m_buff_tower.m_buff_description = dis.readUTF();
			Tools.debugPrintln("第" + i + "个buff的desc：" + m_buff_tower.m_buff_description);
			m_buff.add(m_buff_tower);
		}
		m_sigle_price = dis.readInt();
		UIWindows.getInstance().m_hook.closeHook();
		Turnplate();
	}

	public void recvTowerZhuanPanSouding(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		Tools.debugPrintln("锁定buff的返回状态：" + m_state);
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "锁定失败。");
		} else if (m_state == 1) {
			m_flag[m_buff_index] = true;
			Tools.debugPrintln("锁定第" + m_buff_index + "个。");
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "已经从选项中删除" + m_buff.get(m_buff_index).m_buff_item.m_name + "效果。");
			DWControlsManager.getInstance().removeControl(m_pan_frame);

			DWImageBox m_buff_suohou = new DWImageBox(m_cr_buff_suohou);
			m_buff_suohou.setNearAnchor(m_buff_grid[m_buff_index], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			m_buff_frame.addControl(m_buff_suohou);
		}
	}

	// //转盘旋转的结果接收指令
	public byte m_zhuanpan_end_index = 0;
	public boolean m_end_flag = true;
	public String m_buff_name = null;

	public void recvZhuanPanEnd(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		m_zhuanpan_end_index = dis.readByte();
		m_end_flag = false;
		Tools.debugPrintln("转盘的结果索引值：" + m_zhuanpan_end_index);
		if (!m_boolean_flag_tuichu) {
			m_boolean_flag_tuichu = true;
			m_end_flag = true;
			for (int i = 0; i < m_buff_grid.length; i++) {
				if (m_buff.get(i).m_buff_index == m_zhuanpan_end_index) {
					m_buff_name = m_buff.get(i).m_buff_item.m_name;
				}
			}
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "测试吉凶，本层获得" + m_buff_name + "效果。");
			DWGameManager.getInstance().getSendMessage().sendTowerBeginDaGuai();
		}
	}

	public DWFrame m_buff_frame = null;// 画布
	public DWImageBox m_buff_xbj = null;// 背景图片
	public DWGrid m_buff_grid[] = null;;// /10个格子
	public Bitmap m_cr_xbj = null;
	public DWButton m_begin_ima = null;
	public DWImageBox m_buff_tuichu = null;
	public DWImageBox m_circle[] = new DWImageBox[20];
	public Bitmap m_cr_green = null;
	public Bitmap m_cr_yellow = null;
	public Bitmap m_cr_white = null;
	public boolean m_boolean_flag_tuichu = true;
	public DWBackground m_zhuanpan_bg = null;
	public Bitmap m_cr_zhuanpan = null;

	public void Turnplate() {
		if (DWControlsManager.getInstance().contains(m_buff_frame)) {
			if (m_buff_frame != null) {
				DWControlsManager.getInstance().removeControl(m_buff_frame);
			}
		}
		m_buff_frame = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		m_buff_frame.setClickClose(false);
		DWControlsManager.getInstance().addControl(m_buff_frame);

		m_buff_tuichu = new DWImageBox(m_cr_tuichu);
		m_buff_tuichu.setNearAnchor(m_buff_frame, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);
		m_buff_tuichu.setTouch(true);
		m_buff_tuichu.setShow(true);
		m_buff_tuichu.setTouchZoomIn(20, 20);
		m_buff_frame.addControl(m_buff_tuichu);
		m_buff_tuichu.addListener(new DWListener() {

			public void OnDoubleClick() {

			}

			public void OnClick() {
				m_count_suoding = 0;
				m_buff_flag = true;
				m_circle_flag = true;
				m_djs_time = 0;
				m_over_count = System.currentTimeMillis();
				m_arc1_speed = 1;
				m_boolean_flag_tuichu = false;
				m_timer = 0;
				m_logic_index = true;
				m_instead=0;
				m_time_count = 0;
				if (m_flag != null && m_flag.length > 0) {
					for (int i = 0; i < m_flag.length; i++) {
						m_flag[i] = false;
					}
				}
				DWControlsManager.getInstance().removeControl(m_buff_frame);
				if (m_end_flag) {
					DWGameManager.getInstance().getSendMessage().sendTowerZhuanpanBegin();
				} else {
					m_end_flag = true;
					m_boolean_flag_tuichu = true;
					DWGameManager.getInstance().getSendMessage().sendTowerBeginDaGuai();
				}
			}
		});

		m_buff_xbj = new DWImageBox(m_cr_xbj);
		m_buff_xbj.setNearAnchor(m_buff_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_buff_frame.addControl(m_buff_xbj);

		m_zhuanpan_bg = new DWBackground(m_cr_zhuanpan, DWFont.getDefaultFont().getFontSize() * 28, DWFont.getDefaultFont().getHeight() + 10);
		m_zhuanpan_bg.setNearAnchor(m_buff_frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, 0);
		m_buff_frame.addControl(m_zhuanpan_bg);

		DWLabel m_lable = new DWLabel("进入六道随机获得一个属性效果，点击图标可以去除该选项。");
		m_lable.setBackgroundColor(Tools.ALPHA);
		m_lable.setTextColor(Tools.ORANGE);
		m_lable.setNearAnchor(m_zhuanpan_bg, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_buff_frame.addControl(m_lable);

		m_begin_ima = new DWButton("", m_cr_buff_begin);
		m_begin_ima.setDownImage(m_cr_buff_begin_down);
		m_begin_ima.setNearAnchor(m_buff_xbj, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_begin_ima.addListener(m_buff_begin_lis);
		m_buff_frame.addControl(m_begin_ima);

		m_buff_grid = new DWGrid[m_buff_size];
		for (int i = 0; i < m_buff_size; i++) {
			m_buff_grid[i] = new DWGrid(m_cr_grid);
			m_buff_grid[i].m_data = m_buff.get(i).m_buff_item;
			int m_x = m_buff_xbj.getShowX() + m_buff_xbj.getShowWidth() / 2;
			int m_y = m_buff_xbj.getShowY() + m_buff_xbj.getShowHeight() / 2;
			int targetX = m_x + 3 - (sin(i * (360 / m_buff_size) - (360 / m_buff_size * 2) << BITS) * 140 * m_cr_xbj.getWidth() / 466 >> BITS);
			int targetY = m_y + (cos(i * (360 / m_buff_size) - (360 / m_buff_size * 2) << BITS) * 140 * m_cr_xbj.getHeight() / 447 >> BITS);
			m_buff_grid[i].setPoint((int) targetX - m_cr_grid.getHeight() / 2, (int) targetY - m_cr_grid.getHeight() / 2);
			m_buff_frame.addControl(m_buff_grid[i]);
			m_buff_grid[i].setTouch(true);
			Tools.debugPrintln("第" + i + "个下标：(" + targetX + "," + targetY + ")");

			final int m_idnex = i;
			m_buff_grid[i].addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_flag[m_idnex] == true) {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "此选项已经被锁定删除。");
					} else {
						Grid(m_idnex);
					}
				}
			});
		}

		// 绿灯和黄灯亮的效果
		for (int i = 0; i < m_circle.length; i++) {
			m_circle[i] = new DWImageBox(m_cr_white);
			int m_x = m_buff_xbj.getShowX() + m_buff_xbj.getShowWidth() / 2;
			int m_y = m_buff_xbj.getShowY() + m_buff_xbj.getShowHeight() / 2;
			int targetX = m_x + 3 - (sin(i * (360 / m_circle.length) - (360 / m_circle.length * 2) << BITS) * 205 * m_cr_white.getWidth() / 30 >> BITS);
			int targetY = m_y + (cos(i * (360 / m_circle.length) - (360 / m_circle.length * 2) << BITS) * 205 * m_cr_white.getHeight() / 30 >> BITS);
			m_circle[i].setPoint((int) targetX - m_cr_yellow.getHeight() / 2, (int) targetY - m_cr_yellow.getHeight() / 2);
			m_buff_frame.addControl(m_circle[i]);
		}
	}

	public static final int BITS = 6;
	public static final int ONE = 1 << BITS;
	public static final int MASK = ONE - 1;
	private static final int FIX = 12 - BITS;
	private static final short[] SINES_X_FP = { 0 >> FIX, 71 >> FIX, 143 >> FIX, 214 >> FIX, 286 >> FIX, 357 >> FIX, 428 >> FIX, 499 >> FIX, 570 >> FIX, 641 >> FIX, 711 >> FIX, 782 >> FIX, 852 >> FIX, 921 >> FIX, 991 >> FIX, 1060 >> FIX, 1129 >> FIX, 1198 >> FIX, 1266 >> FIX, 1334 >> FIX, 1401 >> FIX, 1468 >> FIX, 1534 >> FIX, 1600 >> FIX, 1666 >> FIX, 1731 >> FIX, 1796 >> FIX, 1860 >> FIX, 1923 >> FIX, 1986 >> FIX, 2048 >> FIX, 2110 >> FIX, 2171 >> FIX, 2231 >> FIX, 2290 >> FIX, 2349 >> FIX, 2408 >> FIX, 2465 >> FIX, 2522 >> FIX, 2578 >> FIX, 2633 >> FIX, 2687 >> FIX, 2741 >> FIX, 2793 >> FIX, 2845 >> FIX, 2896 >> FIX, 2946 >> FIX, 2996 >> FIX, 3044 >> FIX, 3091 >> FIX, 3138 >> FIX, 3183 >> FIX, 3228 >> FIX, 3271 >> FIX, 3314 >> FIX, 3355 >> FIX, 3396 >> FIX, 3435 >> FIX, 3474 >> FIX, 3511 >> FIX, 3547 >> FIX, 3582 >> FIX, 3617 >> FIX, 3650 >> FIX, 3681 >> FIX, 3712 >> FIX, 3742 >> FIX, 3770 >> FIX, 3798 >> FIX, 3824 >> FIX, 3849 >> FIX, 3873 >> FIX, 3896 >> FIX, 3917 >> FIX, 3937 >> FIX, 3956 >> FIX, 3974 >> FIX, 3991 >> FIX, 4006 >> FIX, 4021 >> FIX, 4034 >> FIX, 4046 >> FIX, 4056 >> FIX, 4065 >> FIX, 4074 >> FIX, 4080 >> FIX, 4086 >> FIX, 4090 >> FIX, 4094 >> FIX, 4095 >> FIX, 4096 >> FIX };

	public static final int toInt(int nFP) {
		return round(nFP) >> BITS;
	}

	public static final int round(int n) {
		return (n + (ONE >> 1)) & ~MASK;
	}

	public static final int sin(int angle) {
		angle %= 360 << BITS; // 360 degrees
		if (angle < 0) {
			angle += 360 << BITS;
		}
		if (angle <= 90 << BITS) {
			return SINES_X_FP[toInt(angle)];
		} else if (angle <= 180 << BITS) {
			return SINES_X_FP[180 - toInt(angle)];
		} else if (angle <= 270 << BITS) {
			return -SINES_X_FP[toInt(angle) - 180];
		} else {
			return -SINES_X_FP[360 - toInt(angle)];
		}
	}

	public static final int cos(int angle) {
		return sin((90 << BITS) - angle);
	}

	public boolean m_buff_flag = true; // /开始转盘的按钮判定的标志
	public DWImageBox m_ima_buff_select[] = null;
	public Bitmap m_cr_select = null;
	public DWAnimationBox m_animationbox[] = null;
	public Bitmap m_cr_buff_suohou = null;
	private DWListener m_buff_begin_lis = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			m_count_suoding = 0;
			m_begin_ima.setBackground(m_cr_buff_begin_down, false);
			m_begin_ima.setTouch(false);
			m_buff_flag = false;
			if (m_ima_buff_select != null) {
				m_ima_buff_select = null;
			}
			m_ima_buff_select = new DWImageBox[m_buff_size];
			m_animationbox = new DWAnimationBox[m_buff_size];
			Animation m_animation = UIWindows.createAnimation("/anim/zhuanlun_1.anim");
			Actor m_actor = new Actor(m_animation);
			for (int i = 0; i < m_buff_size; i++) {
				m_buff_grid[i].setTouch(false);

				// 旋转的过程中的效果
				m_ima_buff_select[i] = new DWImageBox(m_cr_select);
				m_ima_buff_select[i].setShow(false);
				m_ima_buff_select[i].setNearAnchor(m_buff_grid[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
				m_buff_frame.addControl(m_ima_buff_select[i]);

				// 出结果后的动画
				m_animationbox[i] = new DWAnimationBox(m_actor);
				if (DWGameManager.AdpaterType == DWGameManager.AD_HIGH) {
					m_animationbox[i].setShowWideHigh(135 * 15 / 10, 140 * 15 / 10);
				} else {
					m_animationbox[i].setShowWideHigh(135, 140);
				}
				// m_animationbox[i].setShowWideHigh(135, 140);
				m_animationbox[i].setNearAnchor(
						m_buff_grid[i],
						Tools.LEFT_TOP,
						Tools.LEFT_TOP,
						-(m_animationbox[i].getShowWidth() - m_buff_grid[i].getShowWidth()) / 2,
						-(m_animationbox[i].getShowHeight() - m_buff_grid[i].getShowHeight()) / 2 - m_animationbox[i].getShowHeight() / 2);
				m_animationbox[i].setShow(false);
				m_buff_frame.addControl(m_animationbox[i]);
			}
			DWGameManager.getInstance().getSendMessage().sendTowerZhuanpanBegin();
		}
	};

	/**
	 * 点击每一个转盘格子的时候,封锁的提示方法
	 * 
	 * @param i
	 */

	public DWFrame m_pan_frame = null;
	public DWBackground m_pan_xbj = null;
	public DWTitle m_pan_tit = null;
	public DWImageBox m_pan_iam = null;
	public DWGrid m_pan_grid = null;
	public DWImageBox m_pan_tuichu = null;
	public DWTextbox m_pan_text = null;
	public DWTextbox m_pan_desc = null;
	public DWButton m_pan_but = null;
	public DWTextbox m_pan_name = null;
	public int m_buff_index = 0;
	public Bitmap m_cr_suoding = null;
	public Bitmap m_cr_submit = null;
	public Bitmap m_cr_submit_anxia = null;
	public int m_count_suoding = 0;

	public void Grid(int i) {
		if (DWControlsManager.getInstance().contains(m_pan_frame)) {
			if (m_pan_frame != null) {
				DWControlsManager.getInstance().removeControl(m_pan_frame);
			}
		}
		m_pan_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER);
		m_pan_frame.setClickClose(false);
		DWControlsManager.getInstance().addControl(m_pan_frame);

		m_pan_tit = new DWTitle("", m_pan_frame);
		m_pan_frame.addControl(m_pan_tit);
		m_pan_iam = new DWImageBox(m_cr_suoding);
		m_pan_iam.setNearAnchor(m_pan_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_pan_frame.addControl(m_pan_iam);

		m_pan_tuichu = new DWImageBox(m_cr_tuichu);
		m_pan_tuichu.setNearAnchor(m_pan_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_pan_tuichu.setTouchZoomIn(20, 20);
		m_pan_frame.addControl(m_pan_tuichu);
		m_pan_tuichu.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWControlsManager.getInstance().removeControl(m_pan_frame);
			}
		});

		m_pan_xbj = new DWBackground(m_pan_frame.getShowWidth() - 20, m_pan_frame.getShowHeight() - 20);
		m_pan_xbj.setNearAnchor(m_pan_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, (m_pan_tit.getShowHeight() - 20) + 10);
		m_pan_xbj.setFill(false);
		m_pan_frame.addControl(m_pan_xbj);

		m_pan_grid = new DWGrid(m_cr_grid);
		m_pan_grid.m_data = m_buff.get(i).m_buff_item;
		m_pan_grid.setNearAnchor(m_pan_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
		m_pan_frame.addControl(m_pan_grid);

		m_pan_name = new DWTextbox(m_buff.get(i).m_buff_item.m_name);
		m_pan_name.setNearAnchor(m_pan_grid, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
		m_pan_frame.addControl(m_pan_name);

		m_pan_desc = new DWTextbox(m_buff.get(i).m_buff_description, m_pan_xbj.getShowWidth() - 20);
		m_pan_desc.setNearAnchor(m_pan_grid, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 15);
		m_pan_frame.addControl(m_pan_desc);

		m_pan_text = new DWTextbox("您确定要去除这个选项？需要花费" + m_sigle_price + "元宝。", m_pan_xbj.getShowWidth() - 30);
		m_pan_text.setNearAnchor(m_pan_desc, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		m_pan_frame.addControl(m_pan_text);
		if (m_count_suoding < 5) {
			m_pan_but = new DWButton("确定", m_cr_but);
			m_pan_but.setDownImage(m_cr_but_down);
			m_pan_but.setTouch(true);
		} else {
			m_pan_but = new DWButton("确定", m_cr_but_down);
			m_pan_but.setTouch(false);
		}
		final int m_index = i;
		m_pan_but.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				m_count_suoding++;
				if (m_count_suoding > 5) {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "已锁定5次，不能再继续锁定。");
				} else {
					m_flag[m_index] = true;
					DWGameManager.getInstance().getSendMessage().sendTowerBuff(m_buff.get(m_index).m_buff_index);
					m_buff_index = m_index;
					Tools.debugPrintln("m_buff_index:" + m_buff_index);
				}
			}
		});
		m_pan_but.setNearAnchor(m_pan_xbj, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 0, -10);
		m_pan_frame.addControl(m_pan_but);
	}

	public void recvDisloge(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		if (m_state == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功封锁,扣除99元宝。");
		} else if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "封锁失败。");
		}
	}

	// /进入塔式副本的指令接收（成功或者失败）
	public void recvJoinGamecarbon(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		Tools.debugPrintln("进入副本的回复指令的状态值:" + m_state);
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "进入塔式副本失败。");
		} else if (m_state == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功进入副本。");
			if (DWControlsManager.getInstance().contains(m_open_tower_carbon_frame)) {
				DWControlsManager.getInstance().removeControl(m_open_tower_carbon_frame);
			}
			if (DWControlsManager.getInstance().contains(m_lose_frame)) {
				DWControlsManager.getInstance().removeControl(m_lose_frame);
			}
		}
	}

	// //转盘的
	private int m_timer = 0;
	public int m_all = 30;
	public boolean m_circle_flag = true;

	public int m_time_count = 0;
	public int m_arc1_speed = 1;// /多少帧数转一次
	public int m_index = 0;// 慢速度的时候对比下标
    public boolean m_logic_index = true;
    public int m_instead=0;
    private int m_way = 0;
    private int m_frame_count = 0;
    private int m_frame_add = 0;
    private int m_parent_way = 0;
    private int m_select_way = 0;
	public void logic() {
		if (m_buff_size > 0) {
			int m_arc1_all = m_buff_size;// /共有多少个格子
			if (DWControlsManager.getInstance().contains(m_buff_frame)) {
				if (m_buff_frame != null) {
					if (!m_buff_flag) {
						while (true) {
							boolean flag = false;
							if (!m_flag[m_way]) {
								m_ima_buff_select[m_select_way].setShow(false);
								m_ima_buff_select[m_way].setShow(true);
								m_select_way = m_parent_way = m_way;
								flag = true;
							}
							m_way += (m_arc1_speed == 1 ? 1 : (m_frame_add == 3 ? 1 : 0));
							m_way = m_way > m_buff_size - 1 ? 0 : m_way;
							if (m_parent_way == m_way) {
								m_frame_add += (m_frame_add < 3 ? 1 : 0);
								if (!m_flag[m_way])
									flag = true;
							} else {
								m_parent_way = m_way;
								m_frame_add = 0;
								m_frame_count++;
								m_time_count = m_frame_count / m_buff_size;
							}
							if (flag) {
								break;
							}
						}
						if (m_arc1_speed == 3) {
							if (m_way == m_index) {
								m_ima_buff_select[m_select_way].setShow(false);
								m_way = 0;
								m_parent_way = 0;
								m_select_way = 0;
								m_frame_add = 0;
								m_time_count = 0;
								m_frame_count = 0;
								m_buff_flag = true;
								m_end_flag = true;
								m_circle_flag = false;
								m_arc1_speed = 1;
								m_djs_time = 3;
								m_over_count = System.currentTimeMillis();
								m_animationbox[m_index].setShow(true);
								m_buff_name = m_buff.get(m_index).m_buff_item.m_name;
							}
						}
						if (m_time_count >= 2 && !m_end_flag && m_arc1_speed == 1) {
							m_arc1_speed = 3;
							for (int i = 0; i < m_buff_grid.length; i++) {
								if (m_buff.get(i).m_buff_index == m_zhuanpan_end_index) {
									m_buff_name = m_buff.get(i).m_buff_item.m_name;
									m_index = i;
								}
							}
						}
						
//						if (m_flag[m_way] == false) {
//							m_ima_buff_select[m_way].setShow(true);
//						} else if (m_flag[m_way] == true) {
//							if (m_way == m_buff_size - 1) {
//								m_timer = 0;
//								m_way = 0;
//								if (m_flag[m_way] == false) {
//									m_ima_buff_select[m_way].setShow(true);
//								}
//							} else {
//								m_way++;
//								if (m_flag[m_way] == false) {
//									m_ima_buff_select[m_way].setShow(true);
//								}
//								m_timer = (m_way+2) * m_arc1_speed - m_arc1_speed-1;
////								int m_index = 0;
////								for(int i=way;i<m_buff_size;i++)
////								{
////									if(m_flag[i] == true)
////									{
////										m_ima_buff_select[i].setShow(true);
////										m_timer = (i+2) * m_arc1_speed - m_arc1_speed-1;
////										break;
////									}
////									m_index = i;
////								}
////								if(m_index==m_buff_size-1)
////								{
////									for(int i=0;i<m_buff_size;i++)
////									{
////										if(m_flag[i] == true)
////										{
////											m_ima_buff_select[i].setShow(true);
////											m_timer = (i+2) * m_arc1_speed - m_arc1_speed-1;
////											break;
////										}
////									}
////								}
//							}
//						}
//						if(m_logic_index)
//						{
//							for (int i = (m_buff_size - 1); i >= 0; i--) {
//								if (m_flag[i] == false) {
//									Tools.debugPrintln("中断的："+i);
//									m_logic_index = false;
//									m_instead=i;
//									break;
//								} 
//							}
//						}
//						if(!m_logic_index)
//						{
//							if(m_way == m_instead)
//							{
//								if (((m_timer % (m_arc1_all * m_arc1_speed)) % m_arc1_speed) == (m_arc1_speed - 1)) {
//									m_time_count++;
//									Tools.debugPrintln("m_time_count:"+m_time_count);
//								}
//							}
//						}
//						if (!m_end_flag) {
//							if (m_time_count > 1) {
//								if (m_time_count == 2) {
//									if (m_way == m_instead) {
//										if (((m_timer % (m_arc1_all * m_arc1_speed)) % m_arc1_speed) == (m_arc1_speed - 1)) {
//											m_arc1_speed = 3;
//											for (int i = 0; i < m_buff_grid.length; i++) {
//												m_ima_buff_select[i].setShow(false);
//												if (m_buff.get(i).m_buff_index == m_zhuanpan_end_index) {
//													m_buff_name = m_buff.get(i).m_buff_item.m_name;
//													m_index = i;
////													m_timer = -1;
//													Tools.debugPrintln("m_timer的转换的初始值：" + m_timer);
//													Tools.debugPrintln("m_timer的转换的初始值的m_index：" + m_index);
//												}
//											}
//										}
//									}
//								}
//								if (m_time_count > 2) {
//									if (m_way == m_index) {
//										Tools.debugPrintln("m_time_count:"+m_time_count);
//										Tools.debugPrintln("相比较的way：" + m_way);
////									m_timer = 0;
//										m_time_count = 0;
//										m_buff_flag = true;
//										m_end_flag = true;
//										m_circle_flag = false;
//										m_arc1_speed = 1;
//										m_djs_time = 3;
//										m_over_count = System.currentTimeMillis();
//										for (int i = 0; i < m_buff_grid.length; i++) {
//											m_ima_buff_select[i].setShow(false);
//											if (m_buff.get(i).m_buff_index == m_zhuanpan_end_index) {
//												m_animationbox[i].setShow(true);
//												m_buff_name = m_buff.get(i).m_buff_item.m_name;
//											}
//										}
//									}
//								}
//							}
//						}
						if (++m_timer > 1000000) {
							m_timer = 0;
						}
					}
				}
			}
		}
		DJS();
	}

	public int m_djs_time = 0;
	public long m_over_count = 0;

	public void DJS() {
		if (!m_circle_flag) {
			int way = (m_timer % (m_circle.length * 2)) / 2;
			if (way % 2 == 0) {
				for (int i = 0; i < m_circle.length; i++) {
					if (i % 2 == 0) {
						m_circle[i].setImage(m_cr_yellow);
					} else if (i % 2 != 0) {
						m_circle[i].setImage(m_cr_white);
					}
				}
			} else {
				for (int i = 0; i < m_circle.length; i++) {
					if (i % 2 != 0) {
						m_circle[i].setImage(m_cr_green);
					} else if (i % 2 == 0) {
						m_circle[i].setImage(m_cr_white);
					}
				}
			}
			if (++m_timer > (m_circle.length * 2 - 1)) {
				m_timer = 0;
			}
		}
		if (m_djs_time > 0) {
			if (m_over_count == 0) {
				m_over_count = System.currentTimeMillis();// 读取时截取系统时间
			}
			long currentTime = System.currentTimeMillis();// 当前系统时间
			int index = (int) (m_djs_time - (currentTime - m_over_count) / 1000);
			if (index < 0) {
				m_djs_time = 0;
			} else {
				if (index == 0) {
					if (DWControlsManager.getInstance().contains(m_buff_frame)) {
						DWControlsManager.getInstance().removeControl(m_buff_frame);
					}
					for (int i = 0; i < m_buff_size; i++) {
						m_flag[i] = false;
					}
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "测试吉凶，本层获得了" + m_buff_name + "效果。");
					m_djs_time = 0;
					m_over_count = 0;
					m_circle_flag = true;
					m_arc1_speed = 1;
					m_timer = 0;
					m_logic_index = true;
					m_instead=0;
					DWGameManager.getInstance().getSendMessage().sendTowerBeginDaGuai();
				}
			}
		}
	}

	/**
	 * 每一层 副本通关胜利界面
	 */

	public DWFrame m_tower_win_frame = null;
	public DWBackground m_win_xbj_up = null;
	public DWBackground m_win_xbj_down = null;
	public DWListbox m_win_listbox_up = null;
	public DWListbox m_win_listbox_down = null;
	public DWGrid m_win_grid[] = null;
	public DWTextbox m_win_grid_text[] = null;
	public DWImageBox m_win_tit_ima = null;
	public DWImageBox m_win_tuichu = null;
	public Bitmap m_cr_win_tit = null;
	public Bitmap m_cr_buff_begin = null;
	public Bitmap m_cr_buff_begin_down = null;
	public DWImageBox m_win_ima = null;
	public Bitmap m_cr_win = null;
	public DWLabel m_win_lable = null;
	public String m_str[] = { "金币", "惊魂", "元宝", "战功", "帮贡", "修为", "荣誉" };

	public void TowerWin() {
		if (DWControlsManager.getInstance().contains(m_tower_win_frame)) {
			if (m_tower_win_frame != null) {
				DWControlsManager.getInstance().removeControl(m_tower_win_frame);
			}
		}
		m_tower_win_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER);
		m_tower_win_frame.setClickClose(false);
		DWControlsManager.getInstance().addControl(m_tower_win_frame);

		DWTitle m_win_tit = new DWTitle("", m_tower_win_frame);
		m_tower_win_frame.addControl(m_win_tit);
		m_win_tit_ima = new DWImageBox(m_cr_win_tit);
		m_win_tit_ima.setNearAnchor(m_win_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_tower_win_frame.addControl(m_win_tit_ima);

		m_win_tuichu = new DWImageBox(m_cr_tuichu);
		m_win_tuichu.setNearAnchor(m_win_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_win_tuichu.setTouchZoomIn(20, 20);
		m_tower_win_frame.addControl(m_win_tuichu);
		m_win_tuichu.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				DWControlsManager.getInstance().removeControl(m_tower_win_frame);
				DWGameManager.getInstance().getSendMessage().sendTowerNextInformation();
			}
		});

		m_win_xbj_up = new DWBackground(m_tower_win_frame.getShowWidth() - 10, (m_tower_win_frame.getShowHeight() - (m_win_tit.getShowHeight() - 20) - 15) / 2);
		m_win_xbj_up.setNearAnchor(m_tower_win_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 5, (m_win_tit.getShowHeight() - 20) + 5);
		m_tower_win_frame.addControl(m_win_xbj_up);

		m_win_xbj_down = new DWBackground(m_tower_win_frame.getShowWidth() - 10, m_tower_win_frame.getShowHeight() - (m_win_tit.getShowHeight() - 20) - 15 - m_win_xbj_up.getShowHeight());
		m_win_xbj_down.setNearAnchor(m_win_xbj_up, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 5);
		m_tower_win_frame.addControl(m_win_xbj_down);

		m_win_listbox_up = new DWListbox(m_win_xbj_up.getShowWidth() - 60 - m_cr_win.getWidth(), m_win_xbj_up.getShowHeight() - 60);
		m_win_listbox_up.setNearAnchor(m_win_xbj_up, Tools.LEFT_TOP, Tools.LEFT_TOP, 30, 30);
		m_win_listbox_up.setShowBackgroundRect(false);
		m_win_listbox_up.setLineSpacing(8);
		m_tower_win_frame.addControl(m_win_listbox_up);

		for (int i = 0; i < (m_tower_win.get(0).m_money_size + 1); i++) {
			DWListSubItem m_lsi = new DWListSubItem();
			DWTextbox m_win_text = new DWTextbox("", m_win_listbox_up.getShowWidth());
			if (i == 0) {
				m_win_text.setText("完成时间：" + DWControlTools.CHANGE_ROW + "<mark c=" + getcolor(ItemConstants.稀有度_蓝) + ">" + m_win_time / 3600 + "</mark>" + "小时" + "<mark c="
						+ getcolor(ItemConstants.稀有度_蓝) + ">" + m_win_time % 3600 / 60 + "</mark>" + "分" + "<mark c=" + getcolor(ItemConstants.稀有度_蓝) + ">" + m_win_time % 3600 % 60 + "</mark>" + "秒");
			} else {
				m_win_text.setText("<mark c=" + getcolor(ItemConstants.稀有度_蓝) + ">" + m_str[m_tower_win.get(0).m_money_type[i - 1]] + "：" + "</mark>" + "<mark c=FFBB11>"
						+ m_tower_win.get(0).m_money[i - 1] + "</mark>");
			}
			m_win_text.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
			m_lsi.addControls(m_win_text);
			m_win_listbox_up.addSubItem(m_lsi);
		}

		m_win_ima = new DWImageBox(m_cr_win);
		m_win_ima.setNearAnchor(m_win_listbox_up, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_tower_win_frame.addControl(m_win_ima);

		m_win_lable = new DWLabel("获得奖励");
		m_win_lable.setBackgroundColor(Tools.ALPHA);
		m_win_lable.setTextColor(Tools.ORANGE);
		m_win_lable.setNearAnchor(m_win_xbj_down, Tools.LEFT_TOP, Tools.LEFT_TOP, 30, 10);
		m_tower_win_frame.addControl(m_win_lable);

		m_win_listbox_down = new DWListbox(m_win_xbj_down.getShowWidth() - 60, m_win_xbj_down.getShowHeight() - 20 - m_win_lable.getShowHeight() - 5 - 10);
		m_win_listbox_down.setNearAnchor(m_win_lable, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 5, 0);
		m_win_listbox_down.setShowBackgroundRect(false);
		m_win_listbox_down.setLineSpacing(8);
		m_tower_win_frame.addControl(m_win_listbox_down);

		m_win_grid = new DWGrid[m_tower_win.get(0).m_itemsize];
		m_win_grid_text = new DWTextbox[m_tower_win.get(0).m_itemsize];
		for (int m_index = 0; m_index < m_tower_win.get(0).m_itemsize; m_index++) {
			DWListSubItem m_lsi = new DWListSubItem();

			m_win_grid[m_index] = new DWGrid(m_cr_grid);
			m_win_grid[m_index].m_data = m_tower_win.get(0).m_item_list[m_index];
			m_win_grid[m_index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
			final int m_index_instead = m_index;
			m_win_grid[m_index].addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					for (int i = 0; i < m_tower_win.get(0).m_itemsize; i++) {
						m_win_grid[i].setSelect(false);
					}
					m_win_grid[m_index_instead].setSelect(true);
					DiaoLuo(m_tower_win.get(0).m_item_list[m_index_instead].m_key);
				}
			});

			m_win_grid_text[m_index] = new DWTextbox("<mark c=" + getcolor(m_tower_win.get(0).m_item_list[m_index].m_quality) + ">" + m_tower_win.get(0).m_item_list[m_index].m_name + "</mark>" + "×"
					+ m_tower_win.get(0).m_item_list[m_index].m_num, m_win_listbox_down.getShowWidth() - m_win_grid[m_index].getShowWidth() - 5);
			m_win_grid_text[m_index].setNearAnchor(m_win_grid[m_index], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);

			m_lsi.addControls(m_win_grid[m_index]);
			m_lsi.addControls(m_win_grid_text[m_index]);
			m_win_listbox_down.addSubItem(m_lsi);
		}
	}

	/*
	 * 胜利的接收数据
	 */
	long m_win_time = 0;
	byte m_money_size = 0;
	byte m_money_type = 0;
	long m_money_long_size = 0;
	// byte m_win_item_size = 0;
	long m_money_long[] = null;
	// public Item m_win_item[] = null;
	CopyOnWriteArrayList<TowerGameCarbon> m_tower_win = new CopyOnWriteArrayList<TowerGameCarbon>();

	public void recvWin(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);

		m_win_time = dis.readLong();
		Tools.debugPrintln("完成的时间：" + m_win_time);
		m_tower_win.clear();
		TowerGameCarbon m_win = new TowerGameCarbon();
		m_win.recvMoney(dis);
		m_win.recvItemNum(dis);
		m_tower_win.add(m_win);
		TowerWin();
	}

	public static String getcolor(int index) {
		String color = "";
		switch (index) {
			case ItemConstants.稀有度_灰:
				color = "999999";
				break;
			case ItemConstants.稀有度_白:
				color = "ffffff";
				break;
			case ItemConstants.稀有度_蓝:
				color = "00BBFF";
				break;
			case ItemConstants.稀有度_绿:
				color = "55FF00";
				break;
			case ItemConstants.稀有度_紫:
				color = "9900FF";
				break;
			case ItemConstants.稀有度_橙:
				color = "FFBB11";
				break;
			case ItemConstants.稀有度_红:
				color = "FF3300";
				break;
		}
		return color;
	}

	/**
	 * 每一小节胜利后出现的提示框
	 * 
	 * @param dis
	 * @throws IOException
	 */
	byte m_str_big = 0;
	byte m_num_small = 0;

	public void recvEveryPriceWin(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		Tools.debugPrintln("下一层的信息的回复状态：" + m_state);
		if (m_state == 0) {
			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "抱歉，亲，这已经是最后一层了。", null, "取消");
			DWControlsManager.getInstance().addControl(m_mb);

			m_mb.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
						// /退出副本的指令
						DWGameManager.getInstance().getSendMessage().sendTowerLeaveGameCarbon();
					}
					DWControlsManager.getInstance().removeControl(m_mb);
				}
			});
		} else if (m_state == 1) {
			m_str_big = dis.readByte();
			Tools.debugPrintln("大层的信息：" + m_str_big);
			m_num_small = dis.readByte();
			Tools.debugPrintln("小节的信息：" + m_num_small);

			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "继续挑战" + m_fuben_name[m_str_big] + "第" + (m_num_small + 1) + "层？", "确定", "取消");
			DWControlsManager.getInstance().addControl(m_mb);

			m_mb.addListener(new DWListener() {

				public void OnDoubleClick() {
				}

				public void OnClick() {
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
						// /进入下一小节的副本指令
						DWGameManager.getInstance().getSendMessage().sendTowerJoinNextCeng();
					} else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
						// /退出副本的指令
						DWGameManager.getInstance().getSendMessage().sendTowerLeaveGameCarbon();
					}
					DWControlsManager.getInstance().removeControl(m_mb);
				}
			});
			UIWindows.getInstance().m_hook.closeHook();
		}
	}

	// //离开副本的接收指令
	public void recvLeaveGamecarbon(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "离开副本失败。");
		} else if (m_state == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功离开副本。");
		}
	}

	// //重置副本的接收指令
	public void recvMoreGamecarbon(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		byte m_state = dis.readByte();
		if (m_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "重置副本失败。");
		} else if (m_state == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "成功重置副本。");
			m_open_carbon_desc_text.setText("<mark c=FFBB11>" + m_fuben_name[0] + "</mark>" + DWControlTools.CHANGE_ROW + m_fuben_desc[0]);
			for (int i = 0; i < m_size; i++) {
				if (i == 0) {
					m_open_carbon_image[i].setImage(m_cr_tower_light);
				} else {
					m_open_carbon_image[i].setImage(m_cr_tower_not_open);
				}
			}
		}
	}

	// ///进入下一层副本的接收指令
	public byte m_next_state = 0;

	public void recvJoinNextCeng(DataInputStream dis) throws IOException {
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_塔式副本);
		m_next_state = dis.readByte();
		Tools.debugPrintln("进入下一层的副本的回复状态：" + m_next_state);
		if (m_next_state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "亲，抱歉，进入" + m_fuben_name[m_str_big] + "第" + (m_num_small + 1) + "层副本，失败。");
		} else if (m_next_state == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "恭喜亲，成功进入" + m_fuben_name[m_str_big] + "第" + (m_num_small + 1) + "层副本。");
		}
	}

	public void init() {
		m_cr_tit = UIWindows.createImage("/img/newui/liudaolunhui_1.gnp");// /六道轮回的标题
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// /退出
		m_cr_tower_open = UIWindows.createImage("/img/newui/mojiedy_2.gnp"); // /开启的
		m_cr_tower_light = UIWindows.createImage("/img/newui/mojiedy_3.gnp"); // 亮
		m_cr_tower_not_open = UIWindows.createImage("/img/newui/mojiedy_1.gnp");// /未开启的
		m_cr_but = UIWindows.createImage("/img/newui/anniu_5.gnp");
		m_cr_but_down = UIWindows.createImage("/img/newui/anniu_5ax.gnp");
		m_cr_grid = UIWindows.createImage("/img/newui/wupinlan.gnp");
		m_cr_xxbj = UIWindows.createImage("/img/newui/mojiedt_1.gnp");
		m_cr_xbj = UIWindows.createImage("/img/newui/zhuanlun_3.gnp");// /转轮背景
		m_cr_win_tit = UIWindows.createImage("/img/newui/fubentongguan_1.gnp");// /副本通关的标题
		m_cr_buff_begin = UIWindows.createImage("/img/newui/kaishi_2.gnp");// /开始抽buff的开始按钮
		m_cr_buff_begin_down = UIWindows.createImage("/img/newui/kaishi_1.gnp");// /开始抽buff的开始按钮按下效果
		m_cr_tit_ima = UIWindows.createImage("/img/newui/fubendiaoluo_1.gnp");
		m_cr_win = UIWindows.createImage("/img/newui/fubensl_1.gnp");
		m_cr_xxxbj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");
		m_cr_xxxbj_xz = UIWindows.createImage("/img/newui/xiaobeijing_1.gnp");
		m_cr_suoding = UIWindows.createImage("/img/newui/tishi_1.gnp");
		m_cr_submit = UIWindows.createImage("/img/newui/anniu_6.gnp");
		m_cr_submit_anxia = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		m_cr_zhuanpan = UIWindows.createImage("/img/newui/liaotianwaixian_1.gnp");
		m_cr_yellow = UIWindows.createImage("/img/newui/guangdian_1.gnp");
		m_cr_green = UIWindows.createImage("/img/newui/guangdian_2.gnp");
		m_cr_white = UIWindows.createImage("/img/newui/guangdian_3.gnp");
		m_cr_select = UIWindows.createImage("/img/newui/yaobuff_1.gnp");
		m_cr_buff_suohou = UIWindows.createImage("/img/newui/cha_2.gnp");
	}

	public void open(byte index) {
	}

	public void close(byte index) {
	}

	public void dispose() {
	}
}
